package com.qs.eggs.view.prodetail.fragment;


import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.qs.eggs.R;
import com.qs.eggs.adapter.EvaluationTabIndicatorAdapter;
import com.qs.eggs.base.fragment.BaseFragment;
import com.qs.eggs.listener.EvaluationOnTransitionListener;
import com.qs.eggs.view.fragment.PrimaryFragment;
import com.shizhefei.view.indicator.FixedIndicatorView;
import com.shizhefei.view.indicator.IndicatorViewPager;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 */
public class EvaluationFragment extends BaseFragment {
    private FixedIndicatorView indicator;
    private IndicatorViewPager indicatorViewPager;
    private String[] tabName = new String[] {"全部","好评", "中评","差评"};
    private ArrayList<Fragment> fmList;
    private ViewPager viewPager;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_evaluation;
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
        indicator=findView(R.id.guide_indicator);
        viewPager=findView(R.id.guide_viewPager);
        fmList=new ArrayList<>();
        fmList.add(new EvaluationListFragment());
        fmList.add(new EvaluationListFragment());
        fmList.add(new EvaluationListFragment());
        fmList.add(new EvaluationListFragment());
        // 将viewPager和indicator使用
        indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
        ViewPagerSetting();
    }

    private void ViewPagerSetting() {

        // 未选中字体大小
        float unSelectSize = 14;
        // 选中字体大小
        float selectSize = unSelectSize * 1.0f;
        // 未选中的颜色
        int unSelectColor = Color.parseColor("#555555");
        // 选中时的颜色
        int selectColor = ContextCompat.getColor(getContext(),R.color.white);
        // 设置tab字体的变化
        indicator.setOnTransitionListener(new EvaluationOnTransitionListener(
                selectSize, unSelectSize, selectColor, unSelectColor));

        viewPager.setOffscreenPageLimit(4);
        indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
        // 设置适配器
        indicatorViewPager.setAdapter(new EvaluationTabIndicatorAdapter(getChildFragmentManager(),getContext(),fmList,tabName));
        indicatorViewPager.setOnIndicatorPageChangeListener(new IndicatorViewPager.OnIndicatorPageChangeListener() {
            @Override
            public void onIndicatorPageChange(int preItem, int currentItem) {
                viewPager.setCurrentItem(currentItem);
            }
        });
    }
}
